

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=dark>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/my-blog/img/fluid.png">
  <link rel="icon" href="/my-blog/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="木舟">
  <meta name="keywords" content="python Vue Test 测试开发 自动化测试">
  
    <meta name="description" content="前言接上篇博客说过, pytest相比于unittest, 其中一个优点就是具有很多便捷插件. 那么这篇博客, 就是给大家介绍一下, 比较常用的插件. 本文涉及插件:  pytest-ordering, 控制执行顺序 pytest-rerunfailures, 失败重试 pytest-xdist, 多进程并发执行 pytest-repeat, 重复执行用例 pytest-dependency, 用">
<meta property="og:type" content="article">
<meta property="og:title" content="pytest常用插件">
<meta property="og:url" content="https://walker_kwu.gitee.io/my-blog/2023/05/10/autoTest/pytest%E5%B8%B8%E7%94%A8%E6%8F%92%E4%BB%B6/">
<meta property="og:site_name" content="My Blog">
<meta property="og:description" content="前言接上篇博客说过, pytest相比于unittest, 其中一个优点就是具有很多便捷插件. 那么这篇博客, 就是给大家介绍一下, 比较常用的插件. 本文涉及插件:  pytest-ordering, 控制执行顺序 pytest-rerunfailures, 失败重试 pytest-xdist, 多进程并发执行 pytest-repeat, 重复执行用例 pytest-dependency, 用">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-05-10T06:10:07.000Z">
<meta property="article:modified_time" content="2023-05-23T10:37:53.245Z">
<meta property="article:author" content="木舟">
<meta property="article:tag" content="自动化测试">
<meta property="article:tag" content="测试开发">
<meta property="article:tag" content="自动化测试框架">
<meta name="twitter:card" content="summary_large_image">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>pytest常用插件 - My Blog</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/my-blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/my-blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/my-blog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"walker_kwu.gitee.io","root":"/my-blog/","version":"1.9.2","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"left","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/my-blog/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/my-blog/js/utils.js" ></script>
  <script  src="/my-blog/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.2.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/my-blog/">
      <strong>木舟</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/my-blog/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/my-blog/img/default.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="pytest常用插件"></span>
          
        </div>

        
          
  <div class="mt-3">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-author" aria-hidden="true"></i>
        木舟
      </span>
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-05-10 14:10" pubdate>
          2023年5月10日 下午
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          7.9k 字
        
      </span>
    

    

    
    
      
        <span id="busuanzi_container_page_pv" style="display: none">
          <i class="iconfont icon-eye" aria-hidden="true"></i>
          <span id="busuanzi_value_page_pv"></span> 次
        </span>
        
      
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="padding-left: 2rem; margin-right: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">pytest常用插件</h1>
            
              <p class="note note-info">
                
                  
                    本文最后更新于：2023年5月23日 晚上
                  
                
              </p>
            
            
              <div class="markdown-body">
                
                <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>接上篇博客说过, pytest相比于unittest, 其中一个优点就是具有很多便捷插件.</p>
<p>那么这篇博客, 就是给大家介绍一下, 比较常用的插件.</p>
<p>本文涉及插件:</p>
<ul>
<li>pytest-ordering, 控制执行顺序</li>
<li>pytest-rerunfailures, 失败重试</li>
<li>pytest-xdist, 多进程并发执行</li>
<li>pytest-repeat, 重复执行用例</li>
<li>pytest-dependency, 用例依赖</li>
</ul>
<h1 id="pytest-ordering"><a href="#pytest-ordering" class="headerlink" title="pytest-ordering"></a>pytest-ordering</h1><p>pytest对用例的执行顺序, 都是由上到下依次进行, 也就是说, 执行顺序是按照我们的编写顺序来决定的.</p>
<p>但有些时候, 执行顺序我们是希望手动指定的, 但是又不希望手动改动我们的代码</p>
<p>这个时候, <strong>pytest-ordering</strong>插件就可以满足这一需求.</p>
<p>使用前需要通过pip安装</p>
<blockquote>
<p>pip install pytest-ordering</p>
</blockquote>
<p>pytest-ordering会根据不同的order来进行顺序执行</p>
<blockquote>
<p>执行规则: 负数 -&gt; 未标记 -&gt; 非负数(0=&lt;)</p>
</blockquote>
<p>将执行规则细分为几种:</p>
<ul>
<li>order为负数时, 执行时, 永远都处于 <strong>未标记/非负数</strong> 之后, 只与 <strong>负数</strong> 比较, 谁小, 谁先执行</li>
<li>未标记时, 按照原顺序执行</li>
<li>order为非负数, 即大于等于0时, 永远都处于 <strong>负数/未标记</strong> 之前, 只与 <strong>非负数</strong> 比较, 谁小, 谁先执行</li>
</ul>
<p>下面通过几个例子来说明</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> pytest <br><span class="hljs-keyword">class</span> <span class="hljs-title class_">TestCase</span>():<br><br><span class="hljs-meta">    @pytest.mark.run(<span class="hljs-params">order=-<span class="hljs-number">1</span></span>)</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_02</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_a02&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span><br><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_01</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_a01&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span><br><br><span class="hljs-meta">    @pytest.mark.run(<span class="hljs-params">order=-<span class="hljs-number">2</span></span>)</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_a</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_a&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span> <br><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_b</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_b&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span> <br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    pytest.main([<span class="hljs-string">&#x27;-s&#x27;</span>, __file__]) <br><br><span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">结果:</span><br><span class="hljs-string">collected 4 items                                                                                                                                                                                                                  </span><br><span class="hljs-string"></span><br><span class="hljs-string">test3.py -------&gt;test_a01</span><br><span class="hljs-string">.-------&gt;test_b</span><br><span class="hljs-string">.-------&gt;test_a</span><br><span class="hljs-string">.-------&gt;test_a02</span><br><span class="hljs-string">.</span><br><span class="hljs-string"></span><br><span class="hljs-string">可以看得出来, 只要是order为负数, 都排在最后, 并只与负数做比较, 谁小, 谁先执行</span><br><span class="hljs-string">未标记的, 都按照默认顺序, 即由上到下执行</span><br><span class="hljs-string">&quot;&quot;&quot;</span><br></code></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> pytest <br><span class="hljs-keyword">class</span> <span class="hljs-title class_">TestCase</span>():<br><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_02</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_a02&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span><br><br><span class="hljs-meta">    @pytest.mark.run(<span class="hljs-params">order=<span class="hljs-number">1</span></span>)</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_01</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_a01&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span><br><br><span class="hljs-meta">    @pytest.mark.run(<span class="hljs-params">order=<span class="hljs-number">2</span></span>)</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_a</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_a&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span> <br><br><span class="hljs-meta">    @pytest.mark.run(<span class="hljs-params">order=<span class="hljs-number">0</span></span>)</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_b</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_b&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span> <br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    pytest.main([<span class="hljs-string">&#x27;-s&#x27;</span>, __file__]) <br><br><span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">结果:</span><br><span class="hljs-string"></span><br><span class="hljs-string">collected 4 items                                                                                                                                                                                                                  </span><br><span class="hljs-string"></span><br><span class="hljs-string">test3.py -------&gt;test_b</span><br><span class="hljs-string">.-------&gt;test_a01</span><br><span class="hljs-string">.-------&gt;test_a</span><br><span class="hljs-string">.-------&gt;test_a02</span><br><span class="hljs-string">.</span><br><span class="hljs-string"></span><br><span class="hljs-string">可以看得出来, 只要是order为非负数, 都排在最前面, 并只与非负数做比较, 谁小, 谁先执行</span><br><span class="hljs-string">&quot;&quot;&quot;</span><br></code></pre></td></tr></table></figure>

<h1 id="pytest-rerunfailures"><a href="#pytest-rerunfailures" class="headerlink" title="pytest-rerunfailures"></a>pytest-rerunfailures</h1><p>控制失败的函数/方法用例重跑几次</p>
<p>通过pip安装</p>
<blockquote>
<p>pip install pytest-rerunfailures</p>
</blockquote>
<p>该插件可以通过传参的方式, 定义失败用例重跑几次, 以及每次重跑的时间间隔, 单位为s</p>
<p>有两种声明方式:</p>
<ul>
<li>装饰器</li>
<li>命令行</li>
</ul>
<h2 id="命令行"><a href="#命令行" class="headerlink" title="命令行"></a>命令行</h2><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> pytest <br><span class="hljs-keyword">class</span> <span class="hljs-title class_">TestCase</span>():<br><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_a</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_a&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span> <br><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_b</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_b&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">0</span>  <span class="hljs-comment"># 造成断言失败</span><br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    pytest.main([<span class="hljs-string">&#x27;-s&#x27;</span>, <span class="hljs-string">&#x27;--reruns=2&#x27;</span>, <span class="hljs-string">&#x27;--reruns-delay=2&#x27;</span>, __file__]) <span class="hljs-comment"># 声明参数 --reruns 以及 --reruns-delay</span><br><br><span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">结果:</span><br><span class="hljs-string"></span><br><span class="hljs-string">collected 2 items</span><br><span class="hljs-string"></span><br><span class="hljs-string">test3.py -------&gt;test_a</span><br><span class="hljs-string">.-------&gt;test_b</span><br><span class="hljs-string">R-------&gt;test_b</span><br><span class="hljs-string">R-------&gt;test_b</span><br><span class="hljs-string">F</span><br><span class="hljs-string"></span><br><span class="hljs-string">============================================================================================================ FAILURES ============================================================================================================ </span><br><span class="hljs-string">________________________________________________________________________________________________________ TestCase.test_b _________________________________________________________________________________________________________ </span><br><span class="hljs-string"></span><br><span class="hljs-string">self = &lt;test3.TestCase object at 0x00000247AC826DF0&gt;</span><br><span class="hljs-string"></span><br><span class="hljs-string">    def test_b(self):</span><br><span class="hljs-string">        print(&quot;-------&gt;test_b&quot;)</span><br><span class="hljs-string">&gt;       assert 0</span><br><span class="hljs-string">E       assert 0</span><br><span class="hljs-string"></span><br><span class="hljs-string">test3.py:10: AssertionError</span><br><span class="hljs-string">==================================================================================================== short test summary info ===================================================================================================== </span><br><span class="hljs-string">FAILED test3.py::TestCase::test_b - assert 0</span><br><span class="hljs-string">============================================================================================== 1 failed, 1 passed, 2 rerun in 4.33s</span><br><span class="hljs-string">&quot;&quot;&quot;</span><br></code></pre></td></tr></table></figure>

<p>从结果上来看, <code>test_b</code> 函数, 重跑了两次, 因为我们触发了<strong>assert断言</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> pytest <br><span class="hljs-keyword">class</span> <span class="hljs-title class_">TestCase</span>():<br><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_a</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_a&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span> <br><br><span class="hljs-meta">    @pytest.mark.flaky(<span class="hljs-params">reruns=<span class="hljs-number">2</span>, reruns_delay=<span class="hljs-number">2</span></span>)  </span><span class="hljs-comment"># 通过装饰器声明, 参数名一致</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_b</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_b&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">0</span>  <span class="hljs-comment"># 造成断言失败</span><br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    pytest.main([<span class="hljs-string">&#x27;-s&#x27;</span>, __file__])  <span class="hljs-comment"># 这里就不需要声明了</span><br></code></pre></td></tr></table></figure>

<p>结果就不贴出来了, 和命令行运行后的结果是一样的.</p>
<h1 id="pytest-xdist"><a href="#pytest-xdist" class="headerlink" title="pytest-xdist"></a>pytest-xdist</h1><p>用来进行并发运行, 其目的是为了节省运行时间.</p>
<p>比如, 一次运行时, 需要运行1000条用例, 每条用例运行占用1s</p>
<p>这个时候, 如果单核运行, 那就得需要1000s来完成.</p>
<p>这个时候, 如果引入了并发运行, 假设设置了双核运行, 时间就会节省一半.</p>
<p>注意, pytest-xdist的运行方式是 <strong>多进程</strong>, 并不是 <strong>多线程</strong></p>
<p>在python中, 并没有真正意义上的 <strong>多线程</strong>, 因为 <strong>Cython解释器</strong> 的限制, 一个进程只能有一个线程来执行程序.</p>
<p>使用时, 需要pip进行安装</p>
<blockquote>
<p>pip install pytest-xdist</p>
</blockquote>
<p>运行时, 通过参数 <strong>-n</strong> 来知道运行的核数, 可以取值 <strong>auto</strong>, 此时会根据当前电脑配置自动设置运行核心数. 但此时cpu占比会很高.</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> pytest <br><span class="hljs-keyword">class</span> <span class="hljs-title class_">TestCase</span>():<br><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_a</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_a&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span> <br><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_b</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_b&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">0</span>  <span class="hljs-comment"># 造成断言失败</span><br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    pytest.main([<span class="hljs-string">&#x27;-s&#x27;</span>, <span class="hljs-string">&#x27;-n 2&#x27;</span>, <span class="hljs-string">&#x27;-v&#x27;</span>, __file__])  <span class="hljs-comment"># 设置两个核心来运行, 自动分发用例  -v用来打印详细日志</span><br><br><span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">结果:</span><br><span class="hljs-string"></span><br><span class="hljs-string">gw0 [2] / gw1 [2]</span><br><span class="hljs-string">scheduling tests via LoadScheduling</span><br><span class="hljs-string"></span><br><span class="hljs-string">test3.py::TestCase::test_a</span><br><span class="hljs-string">test3.py::TestCase::test_b</span><br><span class="hljs-string">[gw0] PASSED test3.py::TestCase::test_a</span><br><span class="hljs-string">[gw1] FAILED test3.py::TestCase::test_b </span><br><span class="hljs-string">&quot;&quot;&quot;</span><br></code></pre></td></tr></table></figure>

<p>可以看出, 确实是两个核心来运行, 有同学也许会质疑: “我不信, 打印的日志也会骗人”</p>
<p>好! 没事, 我们加入一些运行时间.</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> pytest<br><span class="hljs-keyword">import</span> logging<br><span class="hljs-keyword">import</span> time<br><br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">TestCase</span>():<br><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_a</span>(<span class="hljs-params">self</span>):<br>        time.sleep(<span class="hljs-number">10</span>)<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_a&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span> <br><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_b</span>(<span class="hljs-params">self</span>):<br>        time.sleep(<span class="hljs-number">10</span>)<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_b&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">0</span>  <span class="hljs-comment"># 造成断言失败</span><br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    startTime = time.time()  <span class="hljs-comment"># 设置开始时间</span><br>    pytest.main([<span class="hljs-string">&#x27;-s&#x27;</span>, __file__])  <span class="hljs-comment"># 普通的运行模式</span><br>    <span class="hljs-comment"># pytest.main([&#x27;-s&#x27;, &#x27;-n 2&#x27;, &#x27;-v&#x27;, __file__])  # 设置两个核心来运行, 自动分发用例  -v用来打印详细日志</span><br>    logging.warning(time.time() - startTime)  <span class="hljs-comment"># 打印总运行时间</span><br><br><span class="hljs-comment"># 结果: WARNING:root:20.53572964668274</span><br><span class="hljs-comment"># 运行了20秒, 因为每个用例都等待了10s</span><br></code></pre></td></tr></table></figure>

<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> pytest<br><span class="hljs-keyword">import</span> logging<br><span class="hljs-keyword">import</span> time<br><br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">TestCase</span>():<br><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_a</span>(<span class="hljs-params">self</span>):<br>        time.sleep(<span class="hljs-number">10</span>)<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_a&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span> <br><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_b</span>(<span class="hljs-params">self</span>):<br>        time.sleep(<span class="hljs-number">10</span>)<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_b&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">0</span>  <span class="hljs-comment"># 造成断言失败</span><br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    startTime = time.time()  <span class="hljs-comment"># 设置开始时间</span><br>    <span class="hljs-comment"># pytest.main([&#x27;-s&#x27;, __file__])  # 普通的运行模式</span><br>    pytest.main([<span class="hljs-string">&#x27;-s&#x27;</span>, <span class="hljs-string">&#x27;-n 2&#x27;</span>, <span class="hljs-string">&#x27;-v&#x27;</span>, __file__])  <span class="hljs-comment"># 设置两个核心来运行, 自动分发用例  -v用来打印详细日志</span><br>    logging.warning(time.time() - startTime)  <span class="hljs-comment"># 打印总运行时间</span><br><br><span class="hljs-comment"># 结果: WARNING:root:12.292630434036255</span><br><span class="hljs-comment"># 运行了12秒, 其中两秒钟用来启动核心, 实际运行时间十秒</span><br></code></pre></td></tr></table></figure>

<h1 id="pytest-dependency"><a href="#pytest-dependency" class="headerlink" title="pytest-dependency"></a>pytest-dependency</h1><p>主要用来解决用例之间的依赖关系</p>
<p>我们常常会遇到一种情况, 用例b的数据, 依赖于用例a的执行结果</p>
<p>那这个时候, 如果用例a执行失败了, 用例b我希望能够做到不执行.</p>
<p>这个时候, pytest-dependency, 就可以满足这个需求</p>
<p>使用时需要pip安装</p>
<blockquote>
<p>pip install pytest-dependency</p>
</blockquote>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> pytest<br><br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">TestCase</span>():<br><br><span class="hljs-meta">    @pytest.mark.dependency() </span><span class="hljs-comment">#打上标记</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_get_token</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_get_token&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">0</span><br><br><span class="hljs-meta">    @pytest.mark.dependency(<span class="hljs-params">depends=[<span class="hljs-string">&#x27;test_get_token&#x27;</span>]</span>)  </span><span class="hljs-comment"># 依赖test_get_token是否运行成功</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_b</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_b&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span> <br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    pytest.main([<span class="hljs-string">&#x27;-s&#x27;</span>, __file__])<br><br><span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">结果:</span><br><span class="hljs-string"></span><br><span class="hljs-string">test3.py -------&gt;test_get_token</span><br><span class="hljs-string">Fs</span><br><span class="hljs-string"></span><br><span class="hljs-string">1 failed, 1 skipped in 0.29s </span><br><span class="hljs-string"></span><br><span class="hljs-string">可以发现, 只运行了test_get_token</span><br><span class="hljs-string">test_b因为test_get_token运行失败而跳过了</span><br><span class="hljs-string">&quot;&quot;&quot;</span><br></code></pre></td></tr></table></figure>

<p>不难发现, <strong>depends</strong>参数接收的是一个数组, 所以可以进行 <strong>多依赖</strong></p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> pytest<br><br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">TestCase</span>():<br><br><span class="hljs-meta">    @pytest.mark.dependency() </span><span class="hljs-comment">#打上标记</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_get_token</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_get_token&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span><br><br><span class="hljs-meta">    @pytest.mark.dependency() </span><span class="hljs-comment">#打上标记</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_get_token2</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_get_token2&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">0</span><br><br><span class="hljs-meta">    @pytest.mark.dependency(<span class="hljs-params">depends=[<span class="hljs-string">&#x27;test_get_token&#x27;</span>, <span class="hljs-string">&#x27;test_get_token2&#x27;</span>]</span>)  </span><span class="hljs-comment"># 依赖test_get_token是否运行成功</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_b</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_b&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span> <br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    pytest.main([<span class="hljs-string">&#x27;-s&#x27;</span>, __file__])<br><br><span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string">结果:</span><br><span class="hljs-string"></span><br><span class="hljs-string">collected 3 items</span><br><span class="hljs-string"></span><br><span class="hljs-string">test3.py -------&gt;test_get_token</span><br><span class="hljs-string">.-------&gt;test_get_token2</span><br><span class="hljs-string">Fs</span><br><span class="hljs-string"></span><br><span class="hljs-string">1 failed, 1 passed, 1 skipped</span><br><span class="hljs-string"></span><br><span class="hljs-string">可以发现, depends传入的数组中, 有多个用例时, 必须要全部用例都通过时, 才会执行该用例</span><br><span class="hljs-string">&quot;&quot;&quot;</span><br></code></pre></td></tr></table></figure>

<p><strong>dependency</strong> 还可以通过 <strong>name</strong> 参数, 给用例设置别名</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">import</span> pytest<br><br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">TestCase</span>():<br><br><span class="hljs-meta">    @pytest.mark.dependency(<span class="hljs-params">name=<span class="hljs-string">&#x27;token1&#x27;</span></span>) </span><span class="hljs-comment"># 通过name参数, 取别名</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_get_token</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_get_token&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span><br><br><span class="hljs-meta">    @pytest.mark.dependency(<span class="hljs-params">name=<span class="hljs-string">&#x27;token2&#x27;</span></span>) </span><span class="hljs-comment"># 通过name参数, 取别名</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_get_token2</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_get_token2&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">0</span><br><br><span class="hljs-meta">    @pytest.mark.dependency(<span class="hljs-params">depends=[<span class="hljs-string">&#x27;token1&#x27;</span>, <span class="hljs-string">&#x27;test_get_token2&#x27;</span>]</span>) </span><span class="hljs-comment"># 写入别名或者原本的名字都可以</span><br>    <span class="hljs-keyword">def</span> <span class="hljs-title function_">test_b</span>(<span class="hljs-params">self</span>):<br>        <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;-------&gt;test_b&quot;</span>)<br>        <span class="hljs-keyword">assert</span> <span class="hljs-number">1</span> <br><br><span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&#x27;__main__&#x27;</span>:<br>    pytest.main([<span class="hljs-string">&#x27;-s&#x27;</span>, __file__])<br></code></pre></td></tr></table></figure>
                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/my-blog/categories/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/" class="category-chain-item">自动化测试</a>
  
  
    <span>></span>
    
  <a href="/my-blog/categories/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/pytest/" class="category-chain-item">pytest</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/my-blog/tags/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95/">#自动化测试</a>
      
        <a href="/my-blog/tags/%E6%B5%8B%E8%AF%95%E5%BC%80%E5%8F%91/">#测试开发</a>
      
        <a href="/my-blog/tags/%E8%87%AA%E5%8A%A8%E5%8C%96%E6%B5%8B%E8%AF%95%E6%A1%86%E6%9E%B6/">#自动化测试框架</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>pytest常用插件</div>
      <div>https://walker_kwu.gitee.io/my-blog/2023/05/10/autoTest/pytest常用插件/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>木舟</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年5月10日</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>更新于</div>
          <div>2023年5月23日</div>
        </div>
      
      <div class="license-meta-item">
        <div>许可协议</div>
        <div>
          
            
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="BY - 署名">
                <i class="iconfont icon-by"></i>
              </span>
              </a>
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="NC - 非商业性使用">
                <i class="iconfont icon-nc"></i>
              </span>
              </a>
            
              <a target="_blank" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">
              <span class="hint--top hint--rounded" aria-label="SA - 相同方式共享">
                <i class="iconfont icon-sa"></i>
              </span>
              </a>
            
          
        </div>
      </div>
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/my-blog/2023/05/11/autoTest/pytest%E8%BF%9B%E9%98%B6%E4%BD%BF%E7%94%A8/" title="pytest进阶使用">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">pytest进阶使用</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/my-blog/2023/05/10/autoTest/pytest%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/" title="pytest基本使用">
                        <span class="hidden-mobile">pytest基本使用</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <span>By 木舟</span> <i class="iconfont icon-love"></i> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/my-blog/js/events.js" ></script>
<script  src="/my-blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/my-blog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      headingSelector : CONFIG.toc.headingSelector || 'h1,h2,h3,h4,h5,h6',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      collapseDepth   : CONFIG.toc.collapseDepth || 0,
      scrollSmooth    : true,
      headingsOffset  : -boardTop
    });
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.10/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/my-blog/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/my-blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
